package cn.tang.tframe.sdm.web.filter;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class AccessFilter implements Filter {

//	private static Logger logger = LoggerUtil.accessLog;

	@Override
	public void destroy() {
	}

	@Override
	public void doFilter(ServletRequest req, ServletResponse response, FilterChain chain) throws IOException,
			ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
//		BaseParam requestAttributes = RequestContextAttributeHolder.getRequestAttributes();
//		try {
//			String headerSessionId = WebUtils.getHeaderSessionId();
//			String currentSessionId = (String) WebUtils.getCurrentSessionId();
//			if (StringUtils.isBlank(headerSessionId) && StringUtils.isNotBlank(currentSessionId)) {
//				headerSessionId = currentSessionId;
//			}
//			if (!StringUtils.equalsIgnoreCase(headerSessionId, currentSessionId)) {
//				logger.warn("headerSessionId not equals shiro sessionId: headerSessionId={},currentSessionId={}",
//						headerSessionId, currentSessionId);
//			}
//			if (null != headerSessionId) {
//				requestAttributes.setSessionId(headerSessionId);
//			}
//			ShiroDbRealm.ShiroUser currentUser = WebUtils.getCurrentUser();
//			if(null != currentUser){
//				requestAttributes.setUid(currentUser.getId()+":"+currentUser.getMobile());
//			}
//			RequestContextAttributeHolder.setRequestAttributes(requestAttributes);
//			logger.debug("---AccessFilter--{}--baseparam={}--requestParam={}", request.getRequestURI(),
//					requestAttributes, ServletUtil.dumpRequestParam((HttpServletRequest) req));
//		} catch (Exception e) {
//			logger.warn("AccessFilter param excpetion:{}", e.getMessage());
//		}

		chain.doFilter(req, response);
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}

}
